package com.wei.duowan.bbs.ui.activity;

import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.SimpleItemAnimator;
import android.support.v7.widget.helper.ItemTouchHelper;

import com.google.gson.Gson;
import com.wei.duowan.bbs.R;
import com.wei.duowan.bbs.model.BaseBean;
import com.wei.duowan.bbs.presenter.BasePresenter;
import com.wei.duowan.bbs.ui.adapter.NewsChannelAdapter;
import com.wei.duowan.bbs.utils.StringUtils;
import com.wei.duowan.bbs.widget.NewsChannelItemDecoration;
import com.wei.duowan.bbs.widget.NewsChannelTouchHelperCallback;

import butterknife.Bind;

/**
 * 作者：赵若位
 * 时间：2019/8/26 21:08
 * 联系方式：1070138445
 * 功能：
 */
public class NewsChannelActivity extends BaseActivity
{
    public static final String TAG = NewsChannelActivity.class.getSimpleName();

    @Bind(R.id.recyclerView)
    RecyclerView mRecyclerView;

    private NewsChannelAdapter mAdapter;


    @Override
    protected BasePresenter createPresenter()
    {
        return null;
    }

    @Override
    protected int getLayoutID()
    {
        return R.layout.activity_news_channel;
    }

    @Override
    protected void initView()
    {
        setFinish();
        setTitle(getString(R.string.channel_selection));
        mRecyclerView.setLayoutManager(new GridLayoutManager(this, 4));
        ((SimpleItemAnimator) mRecyclerView.getItemAnimator()).setSupportsChangeAnimations(false);

        /*添加Channel拖动逻辑*/
        NewsChannelTouchHelperCallback call = new NewsChannelTouchHelperCallback();
        ItemTouchHelper helper = new ItemTouchHelper(call);
        helper.attachToRecyclerView(mRecyclerView);

        mAdapter = new NewsChannelAdapter(this,helper);
        mAdapter.setIsEmpty(true);

        NewsChannelItemDecoration decoration = new NewsChannelItemDecoration();
        mRecyclerView.removeItemDecoration(decoration);
        mRecyclerView.addItemDecoration(decoration);

        mAdapter.bindRecyclerView(mRecyclerView);

        String assets = StringUtils.getAssetsJson("头条标题.json");
        Gson gson = new Gson();
        BaseBean data = gson.fromJson(assets, BaseBean.class);

        mAdapter.setNewData(data.getCollection(), data.getNot_collection());
    }

}
